package main

import (
    "strings"
)

type verb string

const (
    LOOK = "look"
    USE = "use"
    PICK = "pick"
)


type Action struct {
    object string
    verb verb
    subject string
}

func parse(s string) (action Action, ok bool) {
    tokens := strings.Split(s, " ")

    for i, token := range(tokens) {
        tokens[i] = strings.Trim(token, " \n")
    }

    switch len(tokens) {
        case 2:
            switch tokens[0] {
                case "look":
                    ok = true
                    action = Action{ object: tokens[1], verb: LOOK }
                case "use":
                    ok = true
                    action = Action{ object: tokens[1], verb: USE }
                case "pick":
                    ok = true
                    action = Action{ object: tokens[1], verb: PICK }
                default:
                    ok = false
            }
        case 4:
            if tokens[0] != "use" || tokens[2] != "on" {
                ok = false 
            } else {
                ok = true
                action = Action{ object: tokens[0], verb: USE, subject: tokens[3] }
            }
        default:
            ok = false
    }

    return
}

